package com.imooc.ad;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

import javax.persistence.Basic;

/**使用feign访问微服务*/
@EnableFeignClients
/**使用Eureka服务*/
@EnableEurekaClient
/**可以使用断路器*/
@EnableHystrix
@EnableCircuitBreaker
/**开启微服务发现能力*/
@EnableDiscoveryClient
/**Hystrix的一些监控*/
@EnableHystrixDashboard
@SpringBootApplication
public class SearchApplication {
    public static void main(String[] args) {
        SpringApplication.run(SearchApplication.class, args);
    }

    /**在使用springcloud ribbon客户端负载均衡的时候，
     * 可以给RestTemplate bean加一个@LoadBalanced注解，就能让这个RestTemplate在请求时拥有客户端负载均衡的能力
     * @LoadBalanced  开启负载均衡能力
     * */
    @Bean
    @LoadBalanced
    RestTemplate restTemplate(){
        return new RestTemplate();
    }
}
